package swordoffer.offer54;

public class RecursionSolution {
    int count = 0;
    int flag = 0;
    int res = 0;
    public int kthLargest(TreeNode root, int k) {
        dfs(root,k);
        return res;
    }
    public void dfs(TreeNode root, int k){
        if(root == null){
            return;
        }
        dfs(root.right,k);
        if(flag == 1){
            return;
        }
        if(++count == k){
            res = root.val;
            flag = 1;
        }
        dfs(root.left,k);
    }
}
